package cool.taomu.toolkit.matcher

import com.google.inject.matcher.Matcher
import java.util.List
import org.eclipse.xtend.lib.annotations.Accessors
import org.slf4j.LoggerFactory

@Accessors
class PackageMatcher implements Matcher<Class<?>> {
    val static LOG = LoggerFactory.getLogger(PackageMatcher)

    List<String> packages

    new(List<String> packages) {
        this.packages = packages
    }

    override matches(Class<?> clazz) {
        if((clazz === null || clazz.getPackage() === null) && this.packages !== null) return false;
        val String pkg = clazz.getPackage().getName();
        val isMatche = packages.findFirst[pkg.startsWith(it)] !== null
        LOG.info("matches: {} ==> {}", pkg, isMatche)
        return isMatche
    }
}
